package com.xt.back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xt.back.entity.Course;
import com.xt.back.mapper.CourseMapper;
import com.xt.back.service.ICourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 课程信息表 服务实现类
 * </p>
 *
 * @author leotong
 * @since 2022-04-03
 */
@Service
@AllArgsConstructor
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements ICourseService {

    private final CourseMapper courseMapper;
    @Override
    public Page<Course> getCourseByPage(Course course) {
        Page<Course> page=new Page<>(course.pageNum,course.pageSize);
        QueryWrapper<Course> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().like(course.getCourseName()!=null&&!Objects.equals(course.getCourseName(),""),Course::getCourseName,course.getCourseName())
                .eq(course.getUserId()!=null&&!Objects.equals(course.getUserId(),""),Course::getUserId,course.getUserId());
        return courseMapper.selectPage(page,queryWrapper);
    }
}
